home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte22 / ex5.c < prev    next >
C/C++ Source or Header  |  1995-05-27  |  3KB  |  66 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    static BOOL bAnsi = TRUE;
  6.    switch (uMsg)
  7.    {
  8.          case WM_COMMAND:
  9.                switch ( LOWORD( wParam ) )
  10.                {
  11.                      case IDM_TEST:
  12.                      {
  13.                            int iResult;
  14.                            TCHAR szBuffer[128];
  15.                            HDC   hDC = GetDC( hWnd );
  16.                            // ANSI string of accented characters to translate,
  17.                            // Similar string without accented characters
  18.  
  19.                            static TCHAR szAccentedChars[] = { 0xe1, 0xe2,
  20.                                                               0xe7, 0xe8,
  21.                                                               0xed, 0xec, 0
  22.                                                             };
  23.                            static TCHAR szUnaccentedChars[] = "aaCeii";
  24.  
  25.                            // lstrcmp fails
  26.                            TextOut( hDC, 0, 0, szBuffer, wsprintf(szBuffer,
  27.                                     "Result of lstrcmp of %s vs %s: %d",
  28.                                     szAccentedChars, szUnaccentedChars,
  29.                                     lstrcmp( szAccentedChars, szUnaccentedChars ) ) );
  30.  
  31.                            // lstrcmpi fails because it only ignores case.
  32.                            TextOut( hDC, 0, 20, szBuffer, wsprintf(szBuffer,
  33.                                     "Result of lstrcmpi of %s vs %s: %d",
  34.                                     szAccentedChars, szUnaccentedChars,
  35.                                     lstrcmpi( szAccentedChars, szUnaccentedChars ) ) );
  36.  
  37.                            // do CompareStrings in French - it works
  38.                            iResult = CompareString( MAKELCID(0x40C, SORT_DEFAULT),
  39.                                                     NORM_IGNORECASE |
  40.                                                     NORM_IGNORENONSPACE |
  41.                                                     NORM_IGNOREWIDTH,
  42.                                                     szAccentedChars, 6,
  43.                                                     szUnaccentedChars, 6 );
  44.  
  45.                            // We must subtract 2 bias from result to make it
  46.                            // look like strcmp.
  47.                            TextOut( hDC, 0, 40, szBuffer, wsprintf(szBuffer,
  48.                                    "Result of CompareStrings of %s vs %s: %d",
  49.                                    szAccentedChars, szUnaccentedChars, iResult-2 ) );
  50.  
  51.                            ReleaseDC( hWnd, hDC );
  52.                      }
  53.                      break;
  54.                      case IDM_EXIT:
  55.                            DestroyWindow( hWnd );
  56.                      break;
  57.                }
  58.                break;
  59.          case WM_DESTROY:
  60.                PostQuitMessage( 0 );
  61.                break;
  62.          default:
  63.                return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  64.    }
  65.    return( NULL );
  66. }